Stockname = char(Stockname);
Indexname = char(Indexname);
weightfunction = char(weightfunction);
[Stock Index Date PriceStock PriceIndex] = getStock_Index(Stockname,Indexname);
%Get the return of stock and index
rStock = PriceStock(2:end)./PriceStock(1:end-1) - 1;
rIndex = PriceIndex(2:end)./PriceIndex(1:end-1) - 1;
%-----------------------------------------------------------
%Estimation Robust Weight 1Year
%-----------------------------------------------------------
%Rolling window
rolling = 260;
[n,m] = size(rStock);
k = n-rolling;
datan = x2mdate(Date,0);
datam=datan(262:end);

for i = 1:k
    j = i+260;
    rStockRobust = rStock(i:j,1);
    rIndexRobust = rIndex(i:j,:);
% switch weightfunction
%     case 1
%         wfun='andrews'
%     case 2
%         wfun='bisquare'
%     case 3
%         wfun='cauchy'
%     case 4
%         wfun='fair'
%     case 5
%         wfun='huber'
%     case 6  
%         wfun='logistic'
%     case 7
%         wfun='talwar'
%     case 8 
%         wfun='welsch'    
% end
    
    betaRobust = robustfit(rIndexRobust,rStockRobust,weightfunction);
    betaRobust_Graph(i,:) = betaRobust;
end
%Output to Excel
ExcelRobust=[datam,betaRobust_Graph(:,2)];